package com.example.demo.strategy.context;

import com.example.demo.entity.yml.YmlModel;
import com.example.demo.strategy.StrategyTest;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;

import java.util.Map;
import static com.example.demo.Enums.StrategyDemo.getStrategy;


/**
 * @version 1.0
 * @Author: LJP
 * @Description:            策略调用
 * @Date: Created in 13:31 2022/1/22
 */
@Service
@EnableConfigurationProperties(YmlModel.class)
public class StrategyTestContext {

    private final YmlModel ymlModel;

    private final Map<String, StrategyTest> strategyTestMap;

    public StrategyTestContext(YmlModel ymlModel, Map<String, StrategyTest> strategyTestMap) {
        this.ymlModel = ymlModel;
        this.strategyTestMap = strategyTestMap;
    }

    /**
     * Set strategy test map.
     */
    public void setStrategyTestMap(){
        strategyTestMap.get(getStrategy(ymlModel.getType())).testMethod();
    }

}
